// 解析 Token
export const parseJwt = (token) => {
    try {
      const base64Payload = token.split('.')[1];
      const payload = atob(base64Payload.replace(/-/g, '+').replace(/_/g, '/'));
      return JSON.parse(payload);
    } catch (e) {
      console.error('Token 解析失败:', e);
      return null;
    }
  };
  
  // 获取并解析 Token
  export const getUserData = () => {
    const token = localStorage.getItem('token');
    return token ? parseJwt(token) : null;
  };